package com.example.springboot_system.utils;

import com.zhenzi.sms.ZhenziSmsClient;

import java.util.HashMap;
import java.util.Map;

public class PhoneCode {
    /**
     * 榛子云短信：短语服务
     */
    public String sms(String phoneNumber, String captcha) throws Exception {
        //使用榛子云短信验证平台，发送短信验证码到注册手机，参考榛子云平台SDK文档
        String appId = "109451"; // 注意修改
        String appSecret = "c4c04684-5afb-49c5-9660-d03ddabba518"; // 注意修改
        String appUrl = "https://sms_developer.zhenzikj.com";
        ZhenziSmsClient client = new ZhenziSmsClient(appUrl, appId, appSecret);

        Map<String, Object> params = new HashMap<>();
        //传入手机号
        params.put("number", phoneNumber);
        //短信模板Id
        String templateId = "5913"; // 注意修改
        params.put("templateId", templateId);
        //传入短信模板相关参数
        String[] templateParams = new String[2];
        templateParams[0] = captcha;
        templateParams[1] = "5分钟";
        params.put("templateParams", templateParams);

        //发送短信
        String result = client.send(params);
        //打印返回结果
        return captcha;
    }
}
